package io.github.thesixonenine.lottery.domain.aggregate;

import io.github.thesixonenine.lottery.domain.valobj.AwardPool;
import java.util.List;

/**
 * 抽奖聚合根持有了抽奖活动的id和该活动下的所有可用奖池列表 它的一个最主要的领域功能就是根据一个抽奖发生场景(DrawLotteryContext), 选择出一个适配的奖池,
 * 即chooseAwardPool方法.
 *
 * @author Simple
 * @version 1.0
 * @date 2022/2/8 17:28
 * @since 1.0
 */
public class DrawLottery {

    private int lotteryId; //抽奖id
    private List<AwardPool> awardPools; //奖池列表

    //getter & setter
    public void setLotteryId(int lotteryId) {
        if (lotteryId <= 0) {
            throw new IllegalArgumentException("非法的抽奖id");
        }
        this.lotteryId = lotteryId;
    }

    /**
     * 根据抽奖入参context选择奖池
     */
    public AwardPool chooseAwardPool(DrawLotteryContext context) {
        if (context.getMtCityInfo() != null) {
            return chooseAwardPoolByCityInfo(awardPools, context.getMtCityInfo());
        } else {
            return chooseAwardPoolByScore(awardPools, context.getGameScore());
        }
    }

    /**
     * 根据抽奖所在城市选择奖池
     */
    private AwardPool chooseAwardPoolByCityInfo(List<AwardPool> awardPools, MtCifyInfo cityInfo) {
        for (AwardPool awardPool : awardPools) {
            if (awardPool.matchedCity(cityInfo.getCityId())) {
                return awardPool;
            }
        }
        return null;
    }

    /**
     * 根据抽奖活动得分选择奖池
     */
    private AwardPool chooseAwardPoolByScore(List<AwardPool> awardPools, int gameScore) {
        return new AwardPool();
    }
}
